/*
*            Scp1000GLIB01.pde
*  Read the Barometric Pressure and Temperature values from SCP1000 sensor
* 
*  based on sample code from Arduino forum
*  http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236443720/8
*/

#include <LiquidCrystal.h>
#include <SCP1000.h>
#include <LcdGraph.h>

// Specify slave select pin for SCP1000 device
#define SelectPin 10

#define CELCIUS_SIGN 0
#define ANALOG0 14

#define NUM_DATA 25

SCP1000 scp1000(SelectPin);
// LiquidCrystal(rs, rw, enable, d4, d5, d6, d7) 
LiquidCrystal lcd(8, 6, 7, 5, 4, 3, 2);
LcdGraph lcdG(NUM_DATA,1);

byte CEL[8]={
B11000,
B11000,
B00110,
B01001,
B01000,
B01001,
B00110,
};

unsigned int P[25] = {
 985, 985, 990, 992, 993, 995, 998, 999,1000,1001,
1002,1003,1003,1003,1005,1007,1008,1007,1009,1008,
1008,1007,1007,1008,1008,
};

void setup()
{
  
  // for debug
   Serial.begin(9600); // Open serial connection to report values to host
   Serial.println("Starting up");

   pinMode(ANALOG0, OUTPUT);
   
   lcd.begin(16,2);
   lcd.print("Starting up");
   lcd.createChar(CELCIUS_SIGN,CEL);

   scp1000.init();
   scp1000.readSensor();
   delay(100);
   
}

void loop()
{
  unsigned int val;
  float tempF;
  unsigned int hpaI;
  float hpaF;

  digitalWrite(ANALOG0,HIGH);

  shiftValues();
  scp1000.readSensor();
  val = scp1000.BaroP;
  P[24] = val;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Now:");
  lcd.print(val);
  lcd.print("hPa/");
  
  // debug
  Serial.print(val);
  Serial.print(" hPa ");

  val = scp1000.TempC;
  lcd.print(val);
  lcd.write(CELCIUS_SIGN);

  // debug
  Serial.print(val);
  Serial.println("C");

  lcd.print("Past:[");
  // lcdG.draw((uint8_t *)& P, lcd);
  lcdG.draw(P, lcd);
  lcd.print("]");

  digitalWrite(ANALOG0,LOW);
  
  // wait one hour
  delay(3600000UL);
}
  
void shiftValues() {
  for ( int i = 0 ; i < 24 ; i++) {
    P[i] = P[i+1];
  }
}


